﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Path.Question;

namespace Path.Answer
{
    class Albin: IPath
    {
        public string GetRelativePath(string currentPath, string targetPath)
        {
            int pos = 0;
            string result = "";
            int end = 0;
            int flag = 0;
            int num = 1;
            
           for (int i = 0; i < currentPath.Length && i < targetPath.Length; i++)
           {
               if (currentPath[i] == targetPath[i])
               {
                   if (currentPath[i] == '/')
                   {
                       pos = i;
                   }
                   end = i;
                   flag = 1;
               }
               else
               {
                   flag = 0;
                   break;
               }
               
           }
            int pos1 = pos;
            if (flag == 1)
            {
                if (end + 1 == currentPath.Length)
                {
                    if (end != 0)
                    {
                        ++end;
                    }
                    while (++end < targetPath.Length)
                    {
                        result += targetPath[end];
                    }
                    return result;
                }
                else
                {
                    while (++end < currentPath.Length)
                    {
                        if (currentPath[end-1] == '/')
                        {
                            if (num == 1)
                            {
                                result += "..";
                                num++;
                            }
                            else
                            {
                                result += "/..";
                            }
                        }
                    }
                    return result;
                }
            }
            while (pos < currentPath.Length)
            {
                if (pos + 1 < currentPath.Length)
                {
                    if (currentPath[pos] == '/')
                    {
                        result += "../";
                    }
                }
                pos++;
            }
            while (++pos1 < targetPath.Length)
            {
                if (end < targetPath.Length - 1)
                {
                    result += targetPath[pos1];
                }
            }


            return result;
        }
    }
}
